package com.glitech.demo.data;

import android.app.Application;
import android.util.Log;

import java.util.List;

public class VoiceCmdRepository {
    private VoiceCmdDao mVoiceCmdDao;
    private List<VoiceCmd> mVoiceCmdList;
    public VoiceCmdRepository(Application application) {
        VoiceCmdRoomDatabase db = VoiceCmdRoomDatabase.getDatabase(application);
        mVoiceCmdDao = db.voiceCmdDao();
        Log.i("vc", "get commands");
        VoiceCmd cmd = new VoiceCmd("果小聪", "前进");
        mVoiceCmdDao.insert(cmd);
        cmd = new VoiceCmd("果小智", "后退");
        mVoiceCmdDao.insert(cmd);
        cmd = new VoiceCmd("果小萌", "旋转");
        mVoiceCmdDao.insert(cmd);
        mVoiceCmdList = mVoiceCmdDao.getCommands();
        Log.i("vc", String.valueOf(mVoiceCmdList.size()));
    }

    public List<VoiceCmd> getCommands() {
        mVoiceCmdList = mVoiceCmdDao.getCommands();
        return mVoiceCmdList;
    }
    public void insert(VoiceCmd cmd) {
        VoiceCmdRoomDatabase.databaseWriteExecutor.execute(() -> {
            mVoiceCmdDao.insert(cmd);
        });
    }
    public String queryAction(String word) {
        return mVoiceCmdDao.queryAction(word);
    }
}
